package com.offcn.servlet;

import com.alibaba.fastjson.JSON;
import com.offcn.entity.CourseDetail;
import com.offcn.entity.ResultBean;
import com.offcn.service.CourseDetailService;
import org.apache.commons.beanutils.BeanUtils;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.Map;

/**
 * @author xyll1
 */
@WebServlet("/courseDetail")
public class CourseDetailServlet extends BaseServlet{
    CourseDetailService courseDetailService = new CourseDetailService();
    ResultBean resultBean = null;
    private  void addCourseDetail(HttpServletRequest request,HttpServletResponse response) throws InvocationTargetException, IllegalAccessException, IOException {
        System.out.println(request.getParameter("start_data"));
        Map<String, String[]> parameterMap = request.getParameterMap();
        CourseDetail courseDetail = new CourseDetail();
        BeanUtils.populate(courseDetail,parameterMap);
        boolean isSuccess= courseDetailService.addCourseDetail(courseDetail);
        if (isSuccess){
            resultBean = new ResultBean(200,"删除成功", true);
        }else {
            resultBean = new ResultBean(500,"删除失败", false);
        }
        String s = JSON.toJSONString(resultBean);
        response.getWriter().write(s);

    }
}
